<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>check</title>
    <style>
        #check .txt{
            padding: 5px;
        }
        #check .btn{
            margin: 8px 0;
        }
    </style>
</head>
<body>
    <div id="check">
        <h3>输入文字的验证</h3>
        <label for="txt"></label><input type="text" placeholder="请输入字符串内容" id="txt" class="txt">
        <div class="btn">
            <button onclick="bb()">验证</button>
        </div>
        <div id="res">
        </div>
    </div>
    <script>
        // 分别获取元素对象的值,并把它保存在变量中
        function bb(){
            var txt=document.getElementById("txt");
            var res=document.getElementById("res");
            // 根据文本框获取的值,进行判断
            var num=txt.value;
            var isnumber=isNaN(Number(num))?false:true;
            res.innerText=isnumber?'数字':"字符";
        }


    </script>
</body>
</html>